home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / spiderweb / src / c++ / c++.spider < prev    next >
Encoding:
Text File  |  1993-04-04  |  12.5 KB  |  369 lines

  1. #
  2. # Copyright 1989 by Norman Ramsey, Odyssey Research Associates
  3. #  modified for c++ by Ed Kademan <kademan@stat.wisc.edu>
  4. #  Thu Aug 10 12:47:13 CDT 1989
  5. # Not to be sold, but may be used freely for any purpose
  6. # For more information, see file COPYRIGHT in the parent directory
  7. language C++ extension cc
  8.  
  9. at_sign @
  10.  
  11. comment begin <"//"> end newline
  12.  
  13. default translation <*> mathness yes
  14.  
  15. token identifier category simp mathness yes
  16. token number category math mathness yes
  17. token newline category newline mathness maybe translation <>
  18. token pseudo_semi category semi mathness maybe translation <"\\relax">
  19.  
  20. module definition stmt use math
  21.  
  22. token + category unorbinop
  23. token - category unorbinop
  24. token * category unorbinop translation <"{*}">
  25. token / category dot
  26. token < category less
  27. token > category greater
  28. token = category equals translation <"\\leftarrow"> tangleto <"="-space>
  29. token . category dot
  30. token ~ category unop translation <"\\TI">
  31. token & category unorbinop translation <"\\amp">
  32. token ^ translation <"\\^"> category binop
  33. token | category binop
  34. token ? translation <"\\?"> category question
  35. token % translation <"\\%"> category binop
  36. token # translation <"\\#"> category sharp
  37. token ! category unop translation <"\\neg">
  38. token \ category backslash translation <"\\backslash">
  39. token ( category open
  40. token ) category close
  41. token [ category open
  42. token ] category close
  43. token { translation <"\\{"-indent> category lbrace
  44. token } translation <"\\}"> category rbrace
  45. token , category comma translation <",\\;">
  46. token ; category semi
  47. token : category colon
  48. token :: category coloncolon translation <"\\CC">
  49. token ++ category unop translation <"\\PP">
  50. token -- category unop translation <"\\MM">
  51. token != translation <"\\I"> category binop
  52. token <= translation <"\\L"> category binop
  53. token >= translation <"\\G"> category binop
  54. token == translation <"\\S"> category binop
  55. token && translation <"\\W"> category binop
  56. token || translation <"\\V"> category binop
  57. token -> translation <"\\MG"> category binop
  58. token >> translation <"\\GG"> category binop
  59. token << translation <"\\LL"> category binop
  60.  
  61. macros begin
  62. \def\CC{\mathrel{:{:}}}
  63. \def\CCE{\mathrel{:{:}=}}
  64. \def\FE{\mathrel{/=}}
  65. \def\PP{\mathord{++}}
  66. \def\PE{\mathrel{+=}}
  67. \def\MM{\mathord{--}}
  68. \def\ME{\mathrel{-=}}
  69. \def\MG{\mathrel{\to}}
  70. \def\GG{\mathrel{>\!>}}
  71. \def\LL{\mathrel{<\!<}}
  72. \def\TE{\mathrel{\ast=}}
  73. \def\CE{\mathrel{\%=}}
  74. \def\HE{\mathrel{\uparrow=}}
  75. \def\AE{\mathrel{\amp=}}
  76. \def\OE{\mathrel{|=}}
  77. \let\openbraces=\{
  78. \let\closebraces=\}
  79. \def\{{\ifmmode\openbraces\else$\openbraces$\fi}
  80. \def\}{\ifmmode\closebraces\else$\closebraces$\fi}
  81. \def\?{\mathrel?}
  82. \def\s{\ }
  83. \def\setfilefonts{\let\\=\. \let\|=\. \let\&=\.}
  84. macros end
  85.  
  86. default translation <*-"\\"-space>
  87.  
  88. ilk case_like category case
  89. ilk do_like category do
  90. ilk else_like category else
  91. ilk enum_like category enum
  92. ilk for_like category for
  93. ilk if_like category if
  94. ilk int_like category decl_head translation <*>
  95. ilk new_like category new
  96. ilk sizeof_like category sizeof
  97. ilk struct_like category struct
  98. ilk switch_like category switch
  99. ilk this_like category simp
  100. ilk typedef_like category typedef
  101.  
  102. default translation <*>
  103.  
  104. reserved asm ilk sizeof_like
  105. reserved auto ilk int_like
  106. reserved break ilk case_like
  107. reserved case ilk case_like
  108. reserved char ilk int_like
  109. reserved class ilk struct_like
  110. reserved const ilk int_like
  111. reserved continue ilk case_like
  112. reserved default ilk case_like
  113. reserved delete ilk this_like
  114. reserved do ilk do_like
  115. reserved double ilk int_like
  116. reserved else ilk else_like
  117. reserved enum ilk enum_like
  118. reserved extern ilk int_like
  119. reserved float ilk int_like
  120. reserved for ilk for_like
  121. reserved friend ilk int_like
  122. reserved goto ilk case_like
  123. reserved if ilk if_like
  124. reserved inline ilk int_like
  125. reserved int ilk int_like
  126. reserved long ilk int_like
  127. reserved new ilk new_like
  128. reserved operator ilk this_like
  129. reserved overload ilk int_like
  130. reserved private ilk case_like
  131. reserved protected ilk case_like
  132. reserved public ilk case_like
  133. reserved register ilk int_like
  134. reserved return ilk case_like
  135. reserved short ilk int_like
  136. reserved sizeof ilk sizeof_like
  137. reserved static ilk int_like
  138. reserved struct ilk struct_like
  139. reserved switch ilk switch_like
  140. reserved this ilk this_like
  141. reserved typedef ilk typedef_like
  142. reserved union ilk struct_like
  143. reserved unsigned ilk int_like
  144. reserved virtual ilk int_like
  145. reserved void ilk int_like
  146. reserved while ilk for_like
  147.  
  148. # we indulge in a trick to avoid treating
  149. #    ASCII (*fp)(); 
  150. # as a statement (function call). We use instead
  151. #    ASCII ===> (*fp)();
  152. token ===> translation <"\\relax"> tangleto <space> category decl_head
  153.  
  154.  
  155. # There appears to be a bug in spidery weave.  If the very last line of a
  156. # web file ends with a preprocessor directive weave fails to print it out.
  157. # The first line below fixes this problem.
  158. preproc [ ignore_scrap ] --> preproc newline
  159. ? ignore_scrap --> #1
  160. #  dropped, because we've overflowed yacc!     
  161. #### DON'T DO THIS!  it makes it impossible to add translation on the left
  162. #### ignore_scrap ? --> #2
  163.  
  164.  
  165. # because of declarations, we have to be very careful about converting
  166. # simp to math
  167.  
  168. (math|simp) unop --> math
  169. math (binop|unorbinop) (math|simp) --> math
  170. math comma <opt-9> (math|simp) --> math
  171. # we're not allowed math simp --> statement because math simp could be fn_decl
  172. math math --> math
  173. (math|simp) semi --> stmt
  174. # so to hack the omission above, we include (usually a cast)
  175. math <"\\"-space> stmt --> stmt
  176.  
  177. (open|simpopen|question|unop|unorbinop|case) [ simp ] --> (open|simpopen|question|unop|unorbinop|case) math
  178. [ simp ] binop --> math binop
  179. # old: 
  180. # [ simp ] equals --> math equals
  181. # math [ equals ] --> math binop
  182.  
  183. simp* colon --> tag
  184.  
  185. # can't have simp open --> open because that causes ( to eat all id's to its left.
  186. simp open --> simpopen
  187.  
  188. (open|simpopen) math close --> math
  189. (open|simpopen) <"\\,"> close --> math
  190. # following needed for for statements
  191. open stmt <"\\"-space> --> open
  192.  
  193. (new|simp|decl_head) <"\\"-space> decl_head --> decl_head
  194. [ simp ] math (equals|comma|semi) --> decl_head math (equals|comma|semi)
  195. [ (decl_head|simp) simp ] (simp|math) --> decl_head (simp|math)
  196. (simp|decl_head) <"\\"-space> (simp|math)* comma --> decl_head
  197. [ (simp|decl_head) <"\\"-space> (simp|math)* ] semi --> math semi
  198. (simp|decl_head) <"\\"-space> (simp|math)* equals --> decl_equals
  199. (open|simpopen) [ (simp|decl_head) <"\\"-space> (simp|math)* equals ] --> (open|simpopen) decl_equals
  200. decl_equals math comma --> decl_head
  201. [ decl_equals math ] semi --> math semi
  202. decl_equals [ simp ] --> decl_equals math
  203.  
  204. # here we try to deal with casts and argument lists, e.g.
  205. #    (ASCII *) malloc(sizeof (ASCII *));
  206. #    char *malloc(int);
  207.  
  208. # If the type is predefined, we know we have a cast
  209. (open|simpopen) decl_head close --> cast
  210. (open|simpopen) [ decl_head <"\\"-space> simp ] --> (open|simpopen) decl_head
  211. (open|simpopen) [ decl_head (unorbinop|math) ] --> (open|simpopen) decl_head
  212. (open|simpopen) decl_head comma --> arglist
  213. arglist (decl_head|unorbinop|math) --> arglist
  214. arglist <"\\"-space> simp --> arglist
  215. arglist comma --> arglist
  216. arglist close --> math
  217.  
  218. # and here are some common cases of casts with non-predefined types
  219. # for other cases you'll have to use "declares"
  220. (open|simpopen) math <"\\"-space> unorbinop comma --> arglist
  221. (open|simpopen) math <"\\"-space> unorbinop unorbinop comma --> arglist
  222. (open|simpopen) math <"\\"-space> unorbinop unorbinop unorbinop comma --> arglist
  223. (open|simpopen) math <"\\"-space> unorbinop close --> cast
  224. (open|simpopen) math <"\\"-space> unorbinop unorbinop close --> cast
  225. (open|simpopen) math <"\\"-space> unorbinop unorbinop unorbinop close --> cast
  226.  
  227. # the math here seems to be a cast.  We don't convert to cast because it looks
  228. # too much like a cycle
  229. (open|simpopen) [ math <"\\"-space> simp ] --> (open|simpopen) math
  230.  
  231. # Here is the destiny of casts
  232. cast <"\\"-space> (math|simp) --> math
  233. cast (newline|ignore_scrap) --> cast
  234. cast --> math
  235.  
  236. question math colon --> binop
  237.  
  238. unop math --> math
  239. <"{"> unorbinop <"}"> math --> math
  240. <"\\buildrel"> (binop|unorbinop) <"\\over{"> equals <"}"> --> binop
  241. equals --> binop
  242. sizeof (math|simp) --> math
  243.  
  244. struct simp* <"\\"-space> lbrace --> structbrace
  245. struct lbrace --> structbrace
  246. struct (simp|decl_head)* colon (simp|decl_head) lbrace --> structbrace
  247. struct (simp|decl_head)* colon case (simp|decl_head) lbrace --> structbrace
  248. structbrace [ simp ] --> structbrace decl_head
  249. structbrace <force> stmt --> structbrace
  250. structbrace <outdent-force> rbrace --> struct_head
  251. structbrace <outdent-force> tagged_stmt --> structbrace
  252. [ struct_head ] simp --> decl_head simp
  253. # some people say e.g. struct blah {...};    is this K&R?
  254. [ struct_head ] semi --> math semi
  255. struct [ simp (newline|ignore_scrap) ] --> struct simp
  256. struct simp --> decl_head
  257. decl_head <"\\"-space> struct --> struct
  258.  
  259. # enumeration types are like structures and unions, but they have math
  260. # instead of many decls...
  261. enum simp* <"\\"-space> lbrace --> enumbrace
  262. enum lbrace  --> enumbrace
  263. enumbrace math rbrace <outdent> --> enum_head
  264. [ enum_head ] simp --> decl_head simp
  265. [ enum_head ] semi --> math semi
  266. enum [ simp (newline|ignore_scrap) ] --> enum simp
  267. enum simp --> decl_head
  268. decl_head <"\\"-space> enum --> enum
  269.  
  270. typedef [ simp ] --> typedef decl_head
  271. typedef stmt --> stmt
  272.  
  273. [ math* <indent> ] (lbrace|decl_head|stmt) --> fn_decl (lbrace|decl_head|stmt)
  274. [ (simp|decl_head) <"\\"-space> math* <indent> ] (lbrace|decl_head|stmt) --> fn_decl (lbrace|decl_head|stmt)
  275. # The following statment will always have braces and never be tagged
  276. fn_decl <outdent-force> stmt --> stmt
  277. math colon fn_decl --> fn_decl
  278.  
  279. (open|simpopen) [ stmt <"\\"-space> stmt ] --> (open|simpopen) stmt
  280.  
  281. lbrace <outdent-force> rbrace --> stmt
  282. lbrace <force> stmt --> lbrace
  283. lbrace <outdent-force> tagged_stmt --> lbrace
  284. lbrace (math|simp) <outdent> rbrace --> math
  285.  
  286. # if math can be followed by a brace, or no.
  287. # ifmath and ifbrace can have an attached else or else if clause
  288. # else, for, and while are formatted like if, but can't have an
  289. # attached else clause, so we use formath and forbrace
  290.  
  291. if math --> ifmath
  292. ifmath <"\\"-space> lbrace --> ifbrace
  293. ifbrace <force> stmt --> ifbrace
  294. ifbrace <outdent-force> tagged_stmt --> ifbrace
  295. ifbrace [ rbrace (newline|ignore_scrap) ] --> ifbrace rbrace
  296. ifbrace rbrace [ else (newline|ignore_scrap) ] --> ifbrace rbrace else
  297. ifbrace <outdent-force> rbrace <"\\"-space> else if --> if
  298. ifbrace <outdent-force> rbrace <"\\"-space> else lbrace --> forbrace
  299. ifbrace <outdent-force> rbrace <"\\"-space> else --> formath
  300. ifbrace <outdent-force> rbrace --> stmt
  301.  
  302. # Assume simple statements attached to if will never be tagged
  303.  
  304. ifmath [ stmt (newline|ignore_scrap) ] --> ifmath stmt
  305. ifmath stmt [ else (newline|ignore_scrap) ] --> ifmath stmt else
  306. ifmath <indent-force> stmt <outdent-force> else if --> if
  307. ifmath <indent-force> stmt <outdent-force> else lbrace --> forbrace
  308. ifmath <indent-force> stmt <outdent-force> else --> formath
  309. ifmath <indent-force> stmt <outdent> --> stmt
  310.  
  311. for math --> formath
  312. formath <"\\"-space> lbrace --> forbrace
  313. forbrace <force> stmt --> forbrace
  314. forbrace <outdent-force> tagged_stmt --> forbrace
  315. forbrace <outdent-force> rbrace --> stmt
  316. formath <indent-force> stmt <outdent> --> stmt
  317.  
  318. # we need an extra indent for switch, becuase the cases will be backed out
  319. switch math lbrace <indent> --> switchbrace
  320. switchbrace <outdent-force> tagged_stmt --> switchbrace
  321. # This next should never happen
  322. switchbrace <force> stmt --> switchbrace
  323. switchbrace <outdent-outdent-force> rbrace --> stmt
  324.  
  325.  
  326.  
  327. # handle do-while (while has category for)
  328. do lbrace --> dobrace
  329. dobrace <force> stmt --> dobrace
  330. dobrace <outdent-force> tagged_stmt --> dobrace
  331. dobrace rbrace for --> math
  332. do <indent-force> stmt <outdent-force> for --> math
  333.  
  334. case semi --> stmt
  335. case math semi --> stmt
  336. case colon --> tag
  337. case math colon --> tag
  338. tag <force> tag --> tag
  339. tag <indent-force> stmt --> tagged_stmt
  340.  
  341. stmt <force> stmt --> stmt
  342. stmt <outdent-force> tagged_stmt --> stmt
  343. semi --> stmt
  344.  
  345. # control sequence \8 puts things on the left margin
  346. <force-"\\8"> sharp <"{\\let\\\\=\\bf"-space> (simp|if|else) <"}"-indent-"{}"-space> --> preproc
  347. preproc backslash <force-"\\8\\hskip1em"-space> newline --> preproc
  348. preproc <force-outdent> newline --> ignore_scrap
  349. preproc !(less|lesssimp|backslash|newline) --> preproc
  350. newline --> ignore_scrap
  351.  
  352. [ less (simp|decl_head) ] (dot|greater) --> lesssimp (dot|greater)
  353. lesssimp dot simp --> lesssimp
  354. <"{\\setfilefonts"-space> lesssimp greater <"}"> --> math
  355. lesssimp --> unop
  356. less --> binop
  357. greater --> binop
  358. dot --> binop
  359.  
  360.  
  361. (decl_head|simp) coloncolon (decl_head|simp) --> simp
  362. math coloncolon (decl_head|simp) --> math
  363. decl_head stmt --> stmt
  364.  
  365. # The following handles "~" for destructors.
  366. coloncolon <"\\,"> unop --> coloncolon
  367. unop decl_head --> decl_head
  368.